
//github.com/TomatoLin/go_work/blob/master/common/red_package.go

package math

import (
	"math"
	"math/rand"
)

//remainSize  int     //剩余的红包数量
//remainMoney float64 //剩余的钱
func GetRandomMoney(remainSize int, remainMoney float64) float64 {
	if remainSize == 1 {
		remainSize--
		if remainMoney < 0.01 {
			return 0.01
		}
		//return math.Floor(remainMoney*100) / 100
		return remainMoney
	}
	//min := float64(0.01)
    min := (remainMoney / float64(remainSize)) / 2
	max := (remainMoney / float64(remainSize)) * 2
	money := rand.Float64() * max
	if money <= min {
	    //money = 0.01
	    money = min
	}
	money = math.Floor(money*100) / 100
	remainSize--
	remainMoney -= money
	return money
}



